//
//  HZKSummaryView.m
//  Stock_Health
//
//  Created by MayerF on 2017/7/31.
//  Copyright © 2017年 MayerF. All rights reserved.
//

#import "HZKSummaryView.h"

@interface HZKSummaryView()
@property (nonatomic, strong)UILabel *pZhangDie;
@property (nonatomic, strong)UILabel *pZhangDieContent;
@property (nonatomic, strong)UILabel *pZhangFu;
@property (nonatomic, strong)UILabel *pZhangFuContent;
@property (nonatomic, strong)UILabel *pMaxPrice;
@property (nonatomic, strong)UILabel *pMaxPriceContent;
@property (nonatomic, strong)UILabel *pMinPrice;
@property (nonatomic, strong)UILabel *pMinPriceContent;
@property (nonatomic, strong)UILabel *pOpenPrice;
@property (nonatomic, strong)UILabel *pOpenPriceContent;
@property (nonatomic, strong)UILabel *pLastPrice;
@property (nonatomic, strong)UILabel *pLastPriceContent;
@property (nonatomic, strong)UILabel *pHuanShouLv;
@property (nonatomic, strong)UILabel *pHuaShouLvContent;
@property (nonatomic, strong)UILabel *pLiangBi;
@property (nonatomic, strong)UILabel *pLiangBiContent;

@property (nonatomic, strong)UIView *pLine1;
@property (nonatomic, strong)UIView *pLine2;
@end

@implementation HZKSummaryView

#pragma mark -
#pragma mark 生命周期
- (instancetype)init{
    self = [super init];
    if (self) {
        [self p_commonInit];
        self.backgroundColor = [HZCommonTool getThemeColor];
    }
    return self;
}
- (void)p_commonInit
{
    _pZhangDie = [UILabel new];
    _pZhangDieContent = [UILabel new];
    _pZhangFu = [UILabel new];
    _pZhangFuContent = [UILabel new];
    _pMaxPrice = [UILabel new];
    _pMaxPriceContent = [UILabel new];
    _pMinPrice = [UILabel new];
    _pMinPriceContent = [UILabel new];
    _pOpenPrice = [UILabel new];
    _pOpenPriceContent = [UILabel new];
    _pLastPrice = [UILabel new];
    _pLastPriceContent = [UILabel new];
    _pHuanShouLv = [UILabel new];
    _pHuaShouLvContent = [UILabel new];
    _pLiangBi = [UILabel new];
    _pLiangBiContent = [UILabel new];
    _pLine1 = [UIView new];
    _pLine2 = [UIView new];
    
    _pZhangDie.textAlignment = _pZhangDieContent.textAlignment = NSTextAlignmentCenter;
    _pZhangFu.textAlignment = _pZhangFuContent.textAlignment = NSTextAlignmentCenter;
    _pMaxPriceContent.font = _pOpenPriceContent.font = _pMinPriceContent.font = _pLastPriceContent.font = _pLiangBiContent.font = _pHuaShouLvContent.font = [UIFont systemFontOfSize:15];
    _pZhangFuContent.font = _pZhangDieContent.font = [UIFont systemFontOfSize:15];
    
    _pMaxPrice.textAlignment = _pOpenPrice.textAlignment = _pHuanShouLv.textAlignment = _pMinPrice.textAlignment = _pLastPrice.textAlignment = _pLiangBi.textAlignment = NSTextAlignmentCenter;
    _pMaxPriceContent.textAlignment = _pOpenPriceContent.textAlignment = _pHuaShouLvContent.textAlignment = _pMinPriceContent.textAlignment = _pLastPriceContent.textAlignment =
    _pLiangBiContent.textAlignment = NSTextAlignmentCenter;
    
    _pMaxPriceContent.adjustsFontSizeToFitWidth = YES;
    _pOpenPriceContent.adjustsFontSizeToFitWidth = YES;
    _pMinPriceContent.adjustsFontSizeToFitWidth = YES;
    _pLastPriceContent.adjustsFontSizeToFitWidth = YES;
    _pHuaShouLvContent.adjustsFontSizeToFitWidth = YES;
    _pLiangBiContent.adjustsFontSizeToFitWidth = YES;
    _pZhangDieContent.adjustsFontSizeToFitWidth = YES;
    _pZhangFuContent.adjustsFontSizeToFitWidth = YES;
    
    [self addSubview:_pZhangDie];
    [self addSubview:_pZhangDieContent];
    [self addSubview:_pZhangFu];
    [self addSubview:_pZhangFuContent];
    [self addSubview:_pMaxPrice];
    [self addSubview:_pMaxPriceContent];
    [self addSubview:_pMinPrice];
    [self addSubview:_pMinPriceContent];
    [self addSubview:_pOpenPrice];
    [self addSubview:_pOpenPriceContent];
    [self addSubview:_pLastPrice];
    [self addSubview:_pLastPriceContent];
    [self addSubview:_pHuanShouLv];
    [self addSubview:_pHuaShouLvContent];
    [self addSubview:_pLiangBi];
    [self addSubview:_pLiangBiContent];
    [self addSubview:_pLine1];
    [self addSubview:_pLine2];
    
    _pOpenPrice.font = _pLastPrice.font = _pMaxPrice.font = _pMinPrice.font = [UIFont systemFontOfSize:15];
    _pZhangDie.font = _pZhangFu.font = _pLiangBi.font = _pHuanShouLv.font = [UIFont systemFontOfSize:15];
    
    _pMaxPrice.textColor = _pMinPrice.textColor = _pOpenPrice.textColor =
    _pLastPrice.textColor = _pLiangBi.textColor = _pHuanShouLv.textColor = kMYHexToRGB(0x888888, 1);
    _pZhangDie.textColor = _pZhangFu.textColor = kMYHexToRGB(0x888888, 1);
    _pLine1.backgroundColor = _pLine2.backgroundColor = [HZCommonTool getThemeSeperateColorWithDefaultColor:nil];
    
    [self p_updateConstraintsWithCodeInfo:nil];
    [self p_updateDefaultInfoWithCodeInfo:nil];
}
#pragma mark -
#pragma mark public
- (void)updateNewData:(HZMinPriceModel *)data
{
    _pZhangDieContent.text = data.model_zhangDie;
    _pZhangFuContent.text = data.model_zhangFu;
    _pMaxPriceContent.text = data.model_maxPrice;
    _pMinPriceContent.text = data.model_minPrice;
    _pOpenPriceContent.text = data.model_openPrice;
    _pLastPriceContent.text = data.model_prePrice;
    _pHuaShouLvContent.text = data.model_chengJiaoLiang;
    _pLiangBiContent.text = data.model_chengJiaoE;
    CGFloat fPrePrice = [data.model_prePrice floatValue];
    _pZhangDieContent.textColor = _pZhangFuContent.textColor = [HZCommonTool getThemeZhangDieColorWithValue1:[data.model_currentPrice floatValue] value2:fPrePrice];
    _pMaxPriceContent.textColor = [HZCommonTool getThemeZhangDieColorWithValue1:[data.model_maxPrice floatValue] value2:fPrePrice];
    _pMinPriceContent.textColor = [HZCommonTool getThemeZhangDieColorWithValue1:[data.model_minPrice floatValue] value2:fPrePrice];
    
    [self updateThemeColor];
}
#pragma mark -
#pragma mark private
- (void)p_updateConstraintsWithCodeInfo:(HZOwnedStockModel *)codeInfo
{
    [_pOpenPrice mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self).offset(5);
        make.left.mas_equalTo(self).offset(10);
        make.bottom.mas_equalTo(_pLastPrice.mas_top);
        make.width.mas_equalTo(30);
    }];
    [_pOpenPriceContent mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_pOpenPrice);
        make.left.mas_equalTo(_pOpenPrice.mas_right);
        make.height.mas_equalTo(_pOpenPrice);
    }];
    [_pMaxPrice mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_pOpenPrice);
        make.left.mas_equalTo(_pOpenPriceContent.mas_right).offset(5);
        make.bottom.mas_equalTo(_pOpenPrice);
    }];
    [_pMaxPriceContent mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_pOpenPrice);
        make.left.mas_equalTo(_pMaxPrice.mas_right);
        make.bottom.mas_equalTo(_pOpenPrice);
    }];
    [_pZhangDie mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_pOpenPrice);
        make.left.mas_equalTo(_pMaxPriceContent.mas_right).offset(5);
        make.bottom.mas_equalTo(_pOpenPrice);
    }];
    [_pZhangDieContent mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_pOpenPrice);
        make.left.mas_equalTo(_pZhangDie.mas_right);
        make.bottom.mas_equalTo(_pOpenPrice);
    }];
    [_pHuanShouLv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_pOpenPrice);
        make.left.mas_equalTo(_pZhangDieContent.mas_right).offset(5);
        make.bottom.mas_equalTo(_pOpenPrice);
        make.width.mas_equalTo(@[_pOpenPrice,_pMaxPrice, _pZhangDie]);
    }];
    [_pHuaShouLvContent mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_pOpenPrice);
        make.left.mas_equalTo(_pHuanShouLv.mas_right);
        make.right.mas_equalTo(self).offset(-10);
        make.bottom.mas_equalTo(_pOpenPrice);
        make.width.mas_equalTo(@[_pOpenPriceContent, _pMaxPriceContent, _pZhangDieContent]);
    }];
    
    [_pLastPrice mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self).offset(10);
        make.bottom.mas_equalTo(self).offset(-5);
        make.width.mas_equalTo(_pOpenPrice);
        make.height.mas_equalTo(_pOpenPrice);
    }];
    [_pLastPriceContent mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_pLastPrice);
        make.left.mas_equalTo(_pLastPrice.mas_right);
        make.height.mas_equalTo(_pLastPrice);
    }];
    [_pMinPrice mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_pLastPrice);
        make.left.mas_equalTo(_pLastPriceContent.mas_right).offset(5);
        make.bottom.mas_equalTo(_pLastPrice);
    }];
    [_pMinPriceContent mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_pLastPrice);
        make.left.mas_equalTo(_pMinPrice.mas_right);
        make.bottom.mas_equalTo(_pLastPrice);
    }];
    [_pZhangFu mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_pLastPrice);
        make.left.mas_equalTo(_pMinPriceContent.mas_right).offset(5);
        make.bottom.mas_equalTo(_pLastPrice);
    }];
    [_pZhangFuContent mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_pLastPrice);
        make.left.mas_equalTo(_pZhangFu.mas_right);
        make.bottom.mas_equalTo(_pLastPrice);
    }];
    [_pLiangBi mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_pLastPrice);
        make.left.mas_equalTo(_pZhangFuContent.mas_right).offset(5);
        make.bottom.mas_equalTo(_pLastPrice);
        make.width.mas_equalTo(@[_pLastPrice,_pMinPrice, _pZhangFu]);
    }];
    [_pLiangBiContent mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_pLastPrice);
        make.left.mas_equalTo(_pLiangBi.mas_right);
        make.right.mas_equalTo(self).offset(-10);
        make.bottom.mas_equalTo(_pLastPrice);
        make.width.mas_equalTo(@[_pOpenPriceContent, _pMinPriceContent, _pZhangFuContent]);
    }];
    
    [_pLine1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_equalTo(self);
        make.height.mas_equalTo(0.5);
    }];
    [_pLine2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.mas_equalTo(self);
        make.height.mas_equalTo(0.5);
    }];

}

- (void)p_updateDefaultInfoWithCodeInfo:(HZOwnedStockModel *)codeInfo
{
    if (codeInfo.nModel_Style == 1) {
        _pMaxPriceContent.text = _pMinPriceContent.text = _pOpenPriceContent.text = _pLastPriceContent.text = kDefaultContent;
        _pMaxPrice.text = kHZMaxPrice;
        _pMinPrice.text = kHZMinPrice;
        _pOpenPrice.text = kHZOpenPrice;
        _pLastPrice.text = kHZE;
    }else {
        _pZhangFuContent.text = _pZhangDieContent.text = kDefaultContent;
        _pMaxPriceContent.text = _pMinPriceContent.text = _pOpenPriceContent.text = _pLastPriceContent.text = _pHuaShouLvContent.text = _pLiangBiContent.text = kDefaultContent;
        _pMaxPrice.text = @"高";
        _pMinPrice.text = @"低";
        _pOpenPrice.text = @"开";
        _pLastPrice.text = @"昨";
        _pHuanShouLv.text = @"量";
        _pLiangBi.text = @"额";
        _pZhangDie.text = @"涨";
        _pZhangFu.text = @"幅";
    }
}
#pragma mark -
- (void)upToParentWithObjc:(id)objc withType:(NSInteger)type withParamter:(id)paramter{
}
- (void)downToChildWithObjc:(id)objc withType:(NSInteger)type withParamter:(id)paramter{
}
- (void)updateThemeColor
{
    _pLastPriceContent.textColor = _pOpenPriceContent.textColor =
    _pLiangBiContent.textColor = _pHuaShouLvContent.textColor = [HZCommonTool getThemeZhangDieColor];
}

@end
